clear
clear matrix
clear mata
program drop _all
set more off
set emptycells drop
set maxvar 100000
tempfile main


cd "<directory>"

*The code in this .do file reads in the dataset created in Data Cleaning Step 2.do and runs the code for Figures 5 and 6;

u final_dataset,clear
tempfile mainforgraph
sa `mainforgraph',replace
sa `main',replace


*	Figure 5:;

u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_4t7=`var'*dspp0_4t7*treated_w
	gen p`var'_4t7=`var'*dspp0_4t7 
	gen t`var'_4t7=`var'*treated_wl 
}
keep if !missing(transfer, intxnyqdum1_4t7, intxnyqdum2_4t7, intxnyqdum3_4t7, intxnyqdum4_4t7, intxnyqdum5_4t7, intxnyqdum6_4t7, intxnyqdum7_4t7, intxnyqdum8_4t7, intxnyqdum10_4t7, intxnyqdum11_4t7, intxnyqdum12_4t7, intxnyqdum13_4t7, intxnyqdum14_4t7, intxnyqdum15_4t7, intxnyqdum16_4t7, intxnyqdum17_4t7, dspp0_4t7, treated_wl, dspp0_4t7_treated_wl, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace

u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
qui tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_4t7=`var'*dspp0_4t7*treated_wl 
	gen p`var'_4t7=`var'*dspp0_4t7 
	gen t`var'_4t7=`var'*treated_wl
}
probit transfer intxnyqdum* dspp0_4t7 treated_wl dspp0_4t7_treated_wl pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_4t7 "2007Q3"
label var intxnyqdum2_4t7 "2007Q4"
label var intxnyqdum3_4t7 "2008Q1"
label var intxnyqdum4_4t7 "2008Q2"
label var intxnyqdum5_4t7 "2008Q3"
label var intxnyqdum6_4t7 "2008Q4"
label var intxnyqdum7_4t7 "2009Q1"
label var intxnyqdum8_4t7 "2009Q2"
label var intxnyqdum10_4t7 "2009Q4"
label var intxnyqdum11_4t7 "2010Q1"
label var intxnyqdum12_4t7 "2010Q2"
label var intxnyqdum13_4t7 "2010Q3"
label var intxnyqdum14_4t7 "2010Q4"
label var intxnyqdum15_4t7 "2011Q1"
label var intxnyqdum16_4t7 "2011Q2"
label var intxnyqdum17_4t7 "2011Q3"

coefplot baseline,keep(intxnyqdum1_4t7 intxnyqdum2_4t7 intxnyqdum3_4t7 intxnyqdum4_4t7 intxnyqdum5_4t7 intxnyqdum6_4t7 intxnyqdum7_4t7 intxnyqdum8_4t7 intxnyqdum10_4t7 intxnyqdum11_4t7 intxnyqdum12_4t7 intxnyqdum13_4t7 intxnyqdum14_4t7 intxnyqdum15_4t7 intxnyqdum16_4t7 intxnyqdum17_4t7) vertical coeflabel(,angle(45)) mlabel(cond(@pval<.001, "***", cond(@pval<.01, "**", cond(@pval<.05, "*", cond(@pval<.1, "+", ""))))) note("+ p < .1, * p < .05, ** p < .01, *** p < .001") xline(8.5)
graph export "<directory>", as(png) name("Graph") replace





u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_5t8=`var'*dspp0_5t8*treated_wl 
	gen p`var'_5t8=`var'*dspp0_5t8 
	gen t`var'_5t8=`var'*treated_wl 
}
keep if !missing(transfer, intxnyqdum1_5t8, intxnyqdum2_5t8, intxnyqdum3_5t8, intxnyqdum4_5t8, intxnyqdum5_5t8, intxnyqdum6_5t8, intxnyqdum7_5t8, intxnyqdum8_5t8, intxnyqdum10_5t8, intxnyqdum11_5t8, intxnyqdum12_5t8, intxnyqdum13_5t8, intxnyqdum14_5t8, intxnyqdum15_5t8, intxnyqdum16_5t8, intxnyqdum17_5t8, dspp0_5t8, treated_wl, dspp0_5t8_treated_wl, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace

u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
qui tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_5t8=`var'*dspp0_5t8*treated_wl 
	gen p`var'_5t8=`var'*dspp0_5t8 
	gen t`var'_5t8=`var'*treated_wl 
}
probit transfer intxnyqdum* dspp0_5t8 treated_wl dspp0_5t8_treated_wl pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_5t8 "2007Q3"
label var intxnyqdum2_5t8 "2007Q4"
label var intxnyqdum3_5t8 "2008Q1"
label var intxnyqdum4_5t8 "2008Q2"
label var intxnyqdum5_5t8 "2008Q3"
label var intxnyqdum6_5t8 "2008Q4"
label var intxnyqdum7_5t8 "2009Q1"
label var intxnyqdum8_5t8 "2009Q2"
label var intxnyqdum10_5t8 "2009Q4"
label var intxnyqdum11_5t8 "2010Q1"
label var intxnyqdum12_5t8 "2010Q2"
label var intxnyqdum13_5t8 "2010Q3"
label var intxnyqdum14_5t8 "2010Q4"
label var intxnyqdum15_5t8 "2011Q1"
label var intxnyqdum16_5t8 "2011Q2"
label var intxnyqdum17_5t8 "2011Q3"

coefplot baseline,keep(intxnyqdum1_5t8 intxnyqdum2_5t8 intxnyqdum3_5t8 intxnyqdum4_5t8 intxnyqdum5_5t8 intxnyqdum6_5t8 intxnyqdum7_5t8 intxnyqdum8_5t8 intxnyqdum10_5t8 intxnyqdum11_5t8 intxnyqdum12_5t8 intxnyqdum13_5t8 intxnyqdum14_5t8 intxnyqdum15_5t8 intxnyqdum16_5t8 intxnyqdum17_5t8) vertical coeflabel(,angle(45)) mlabel(cond(@pval<.001, "***", cond(@pval<.01, "**", cond(@pval<.05, "*", cond(@pval<.1, "+", ""))))) note("+ p < .1, * p < .05, ** p < .01, *** p < .001") xline(8.5)
graph export "<directory>", as(png) name("Graph") replace





u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_6t9=`var'*dspp0_6t9*treated_wl 
	gen p`var'_6t9=`var'*dspp0_6t9 
	gen t`var'_6t9=`var'*treated_wl
}
keep if !missing(transfer, intxnyqdum1_6t9, intxnyqdum2_6t9, intxnyqdum3_6t9, intxnyqdum4_6t9, intxnyqdum5_6t9, intxnyqdum6_6t9, intxnyqdum7_6t9, intxnyqdum8_6t9, intxnyqdum10_6t9, intxnyqdum11_6t9, intxnyqdum12_6t9, intxnyqdum13_6t9, intxnyqdum14_6t9, intxnyqdum15_6t9, intxnyqdum16_6t9, intxnyqdum17_6t9, dspp0_6t9, treated_wl, dspp0_6t9_treated_wl, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace


u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
qui tab distyq,g(yqdum)
drop yqdum9
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_6t9=`var'*dspp0_6t9*treated_wl 
	gen p`var'_6t9=`var'*dspp0_6t9 
	gen t`var'_6t9=`var'*treated_wl 
}
probit transfer intxnyqdum* dspp0_6t9 treated_wl dspp0_6t9_treated_wl pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_6t9 "2007Q3"
label var intxnyqdum2_6t9 "2007Q4"
label var intxnyqdum3_6t9 "2008Q1"
label var intxnyqdum4_6t9 "2008Q2"
label var intxnyqdum5_6t9 "2008Q3"
label var intxnyqdum6_6t9 "2008Q4"
label var intxnyqdum7_6t9 "2009Q1"
label var intxnyqdum8_6t9 "2009Q2"
label var intxnyqdum10_6t9 "2009Q4"
label var intxnyqdum11_6t9 "2010Q1"
label var intxnyqdum12_6t9 "2010Q2"
label var intxnyqdum13_6t9 "2010Q3"
label var intxnyqdum14_6t9 "2010Q4"
label var intxnyqdum15_6t9 "2011Q1"
label var intxnyqdum16_6t9 "2011Q2"
label var intxnyqdum17_6t9 "2011Q3"


coefplot baseline,keep(intxnyqdum1_6t9 intxnyqdum2_6t9 intxnyqdum3_6t9 intxnyqdum4_6t9 intxnyqdum5_6t9 intxnyqdum6_6t9 intxnyqdum7_6t9 intxnyqdum8_6t9 intxnyqdum10_6t9 intxnyqdum11_6t9 intxnyqdum12_6t9 intxnyqdum13_6t9 intxnyqdum14_6t9 intxnyqdum15_6t9 intxnyqdum16_6t9 intxnyqdum17_6t9) vertical coeflabel(,angle(45)) mlabel(cond(@pval<.001, "***", cond(@pval<.01, "**", cond(@pval<.05, "*", cond(@pval<.1, "+", ""))))) note("+ p < .1, * p < .05, ** p < .01, *** p < .001") xline(8.5)
graph export "<directory>", as(png) name("Graph") replace



u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_7t10=`var'*dspp0_7t10*treated_wl
	gen p`var'_7t10=`var'*dspp0_7t10 
	gen t`var'_7t10=`var'*treated_wl
}
keep if !missing(transfer, intxnyqdum1_7t10, intxnyqdum2_7t10, intxnyqdum3_7t10, intxnyqdum4_7t10, intxnyqdum5_7t10, intxnyqdum6_7t10, intxnyqdum7_7t10, intxnyqdum8_7t10, intxnyqdum10_7t10, intxnyqdum11_7t10, intxnyqdum12_7t10, intxnyqdum13_7t10, intxnyqdum14_7t10, intxnyqdum15_7t10, intxnyqdum16_7t10, intxnyqdum17_7t10, dspp0_7t10, treated_wl, dspp0_7t10_treated_wl, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace


u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
	
qui tab distyq,g(yqdum)
drop yqdum9
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_7t10=`var'*dspp0_7t10*treated_wl
	gen p`var'_7t10=`var'*dspp0_7t10 
	gen t`var'_7t10=`var'*treated_wl 
}

probit transfer intxnyqdum* dspp0_7t10 treated_wl dspp0_7t10_treated_wl pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_7t10 "2007Q3"
label var intxnyqdum2_7t10 "2007Q4"
label var intxnyqdum3_7t10 "2008Q1"
label var intxnyqdum4_7t10 "2008Q2"
label var intxnyqdum5_7t10 "2008Q3"
label var intxnyqdum6_7t10 "2008Q4"
label var intxnyqdum7_7t10 "2009Q1"
label var intxnyqdum8_7t10 "2009Q2"
label var intxnyqdum10_7t10 "2009Q4"
label var intxnyqdum11_7t10 "2010Q1"
label var intxnyqdum12_7t10 "2010Q2"
label var intxnyqdum13_7t10 "2010Q3"
label var intxnyqdum14_7t10 "2010Q4"
label var intxnyqdum15_7t10 "2011Q1"
label var intxnyqdum16_7t10 "2011Q2"
label var intxnyqdum17_7t10 "2011Q3"

coefplot baseline,keep(intxnyqdum1_7t10 intxnyqdum2_7t10 intxnyqdum3_7t10 intxnyqdum4_7t10 intxnyqdum5_7t10 intxnyqdum6_7t10 intxnyqdum7_7t10 intxnyqdum8_7t10 intxnyqdum10_7t10 intxnyqdum11_7t10 intxnyqdum12_7t10 intxnyqdum13_7t10 intxnyqdum14_7t10 intxnyqdum15_7t10 intxnyqdum16_7t10 intxnyqdum17_7t10) vertical coeflabel(,angle(45)) mlabel(cond(@pval<.001, "***", cond(@pval<.01, "**", cond(@pval<.05, "*", cond(@pval<.1, "+", ""))))) note("+ p < .1, * p < .05, ** p < .01, *** p < .001") xline(6.5)
graph export "<directory>", as(png) name("Graph") replace






*	Figure 6:;

u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_4t7=`var'*dspp0_4t7*treated_dlq 
	gen p`var'_4t7=`var'*dspp0_4t7 
	gen t`var'_4t7=`var'*treated_dlq
}
keep if !missing(transfer, intxnyqdum1_4t7, intxnyqdum2_4t7, intxnyqdum3_4t7, intxnyqdum4_4t7, intxnyqdum5_4t7, intxnyqdum6_4t7, intxnyqdum7_4t7, intxnyqdum8_4t7, intxnyqdum10_4t7, intxnyqdum11_4t7, intxnyqdum12_4t7, intxnyqdum13_4t7, intxnyqdum14_4t7, intxnyqdum15_4t7, intxnyqdum16_4t7, intxnyqdum17_4t7, dspp0_4t7, treated_dlq, dspp0_4t7_treated_dlq, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace

u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
qui tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_4t7=`var'*dspp0_4t7*treated_dlq 
	gen p`var'_4t7=`var'*dspp0_4t7 
	gen t`var'_4t7=`var'*treated_dlq 
}
probit transfer intxnyqdum* dspp0_4t7 treated_dlq dspp0_4t7_treated_dlq pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_4t7 "2007Q3"
label var intxnyqdum2_4t7 "2007Q4"
label var intxnyqdum3_4t7 "2008Q1"
label var intxnyqdum4_4t7 "2008Q2"
label var intxnyqdum5_4t7 "2008Q3"
label var intxnyqdum6_4t7 "2008Q4"
label var intxnyqdum7_4t7 "2009Q1"
label var intxnyqdum8_4t7 "2009Q2"
label var intxnyqdum10_4t7 "2009Q4"
label var intxnyqdum11_4t7 "2010Q1"
label var intxnyqdum12_4t7 "2010Q2"
label var intxnyqdum13_4t7 "2010Q3"
label var intxnyqdum14_4t7 "2010Q4"
label var intxnyqdum15_4t7 "2011Q1"
label var intxnyqdum16_4t7 "2011Q2"
label var intxnyqdum17_4t7 "2011Q3"

coefplot baseline,keep(intxnyqdum1_4t7 intxnyqdum2_4t7 intxnyqdum3_4t7 intxnyqdum4_4t7 intxnyqdum5_4t7 intxnyqdum6_4t7 intxnyqdum7_4t7 intxnyqdum8_4t7 intxnyqdum10_4t7 intxnyqdum11_4t7 intxnyqdum12_4t7 intxnyqdum13_4t7 intxnyqdum14_4t7 intxnyqdum15_4t7 intxnyqdum16_4t7 intxnyqdum17_4t7) vertical coeflabel(,angle(45)) 
graph export "<directory>", as(png) name("Graph") replace


u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_5t8=`var'*dspp0_5t8*treated_dlq
	gen p`var'_5t8=`var'*dspp0_5t8 
	gen t`var'_5t8=`var'*treated_dlq 
}
keep if !missing(transfer, intxnyqdum1_5t8, intxnyqdum2_5t8, intxnyqdum3_5t8, intxnyqdum4_5t8, intxnyqdum5_5t8, intxnyqdum6_5t8, intxnyqdum7_5t8, intxnyqdum8_5t8, intxnyqdum10_5t8, intxnyqdum11_5t8, intxnyqdum12_5t8, intxnyqdum13_5t8, intxnyqdum14_5t8, intxnyqdum15_5t8, intxnyqdum16_5t8, intxnyqdum17_5t8, dspp0_5t8, treated_dlq, dspp0_5t8_treated_dlq, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace

u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
qui tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_5t8=`var'*dspp0_5t8*treated_dlq 
	gen p`var'_5t8=`var'*dspp0_5t8 
	gen t`var'_5t8=`var'*treated_dlq 
}
probit transfer intxnyqdum* dspp0_5t8 treated_dlq dspp0_5t8_treated_dlq pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_5t8 "2007Q3"
label var intxnyqdum2_5t8 "2007Q4"
label var intxnyqdum3_5t8 "2008Q1"
label var intxnyqdum4_5t8 "2008Q2"
label var intxnyqdum5_5t8 "2008Q3"
label var intxnyqdum6_5t8 "2008Q4"
label var intxnyqdum7_5t8 "2009Q1"
label var intxnyqdum8_5t8 "2009Q2"
label var intxnyqdum10_5t8 "2009Q4"
label var intxnyqdum11_5t8 "2010Q1"
label var intxnyqdum12_5t8 "2010Q2"
label var intxnyqdum13_5t8 "2010Q3"
label var intxnyqdum14_5t8 "2010Q4"
label var intxnyqdum15_5t8 "2011Q1"
label var intxnyqdum16_5t8 "2011Q2"
label var intxnyqdum17_5t8 "2011Q3"

coefplot baseline,keep(intxnyqdum1_5t8 intxnyqdum2_5t8 intxnyqdum3_5t8 intxnyqdum4_5t8 intxnyqdum5_5t8 intxnyqdum6_5t8 intxnyqdum7_5t8 intxnyqdum8_5t8 intxnyqdum10_5t8 intxnyqdum11_5t8 intxnyqdum12_5t8 intxnyqdum13_5t8 intxnyqdum14_5t8 intxnyqdum15_5t8 intxnyqdum16_5t8 intxnyqdum17_5t8) vertical coeflabel(,angle(45)) 
graph export "<directory>", as(png) name("Graph") replace



u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_6t9=`var'*dspp0_6t9*treated_dlq 
	gen p`var'_6t9=`var'*dspp0_6t9
	gen t`var'_6t9=`var'*treated_dlq
}
	keep if !missing(transfer, intxnyqdum1_6t9, intxnyqdum2_6t9, intxnyqdum3_6t9, intxnyqdum4_6t9, intxnyqdum5_6t9, intxnyqdum6_6t9, intxnyqdum7_6t9, intxnyqdum8_6t9, intxnyqdum10_6t9, intxnyqdum11_6t9, intxnyqdum12_6t9, intxnyqdum13_6t9, intxnyqdum14_6t9, intxnyqdum15_6t9, intxnyqdum16_6t9, intxnyqdum17_6t9, dspp0_6t9, treated_dlq, dspp0_6t9_treated_dlq, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace

u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
qui tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_6t9=`var'*dspp0_6t9*treated_dlq 
	gen p`var'_6t9=`var'*dspp0_6t9
	gen t`var'_6t9=`var'*treated_dlq 
}
probit transfer intxnyqdum* dspp0_6t9 treated_dlq dspp0_6t9_treated_dlq pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_6t9 "2007Q3"
label var intxnyqdum2_6t9 "2007Q4"
label var intxnyqdum3_6t9 "2008Q1"
label var intxnyqdum4_6t9 "2008Q2"
label var intxnyqdum5_6t9 "2008Q3"
label var intxnyqdum6_6t9 "2008Q4"
label var intxnyqdum7_6t9 "2009Q1"
label var intxnyqdum8_6t9 "2009Q2"
label var intxnyqdum10_6t9 "2009Q4"
label var intxnyqdum11_6t9 "2010Q1"
label var intxnyqdum12_6t9 "2010Q2"
label var intxnyqdum13_6t9 "2010Q3"
label var intxnyqdum14_6t9 "2010Q4"
label var intxnyqdum15_6t9 "2011Q1"
label var intxnyqdum16_6t9 "2011Q2"
label var intxnyqdum17_6t9 "2011Q3"

coefplot baseline,keep(intxnyqdum1_6t9 intxnyqdum2_6t9 intxnyqdum3_6t9 intxnyqdum4_6t9 intxnyqdum5_6t9 intxnyqdum6_6t9 intxnyqdum7_6t9 intxnyqdum8_6t9 intxnyqdum10_6t9 intxnyqdum11_6t9 intxnyqdum12_6t9 intxnyqdum13_6t9 intxnyqdum14_6t9 intxnyqdum15_6t9 intxnyqdum16_6t9 intxnyqdum17_6t9) vertical coeflabel(,angle(45)) 
graph export "<directory>", as(png) name("Graph") replace





u `main',clear
tempfile msayq  
tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_7t10=`var'*dspp0_7t10*treated_dlq 
	gen p`var'_7t10=`var'*dspp0_7t10 
	gen t`var'_7t10=`var'*treated_dlq 
}
keep if !missing(transfer, intxnyqdum1_7t10, intxnyqdum2_7t10, intxnyqdum3_7t10, intxnyqdum4_7t10, intxnyqdum5_7t10, intxnyqdum6_7t10, intxnyqdum7_7t10, intxnyqdum8_7t10, intxnyqdum10_7t10, intxnyqdum11_7t10, intxnyqdum12_7t10, intxnyqdum13_7t10, intxnyqdum14_7t10, intxnyqdum15_7t10, intxnyqdum16_7t10, intxnyqdum17_7t10, dspp0_7t10, treated_dlq, dspp0_7t10_treated_dlq, orig_ltv, securwac, securocc, orig_dscrnoi2, age, balratio, ltv, occrate, dscrnoi, propid, dealtypeid, originatorid, origyq, msayq, ssid)
keep if dcountss_2==1
keep if yearmonth>=572 & yearmonth<=620
collapse (mean) transfer,by(msayq)
gen indic=1 if transfer==0
keep msayq indic
sa `msayq',replace


u `main',clear
merge m:1 msayq using `msayq'
drop if _merge==2
drop _merge
qui tab distyq,g(yqdum)
drop yqdum9 
foreach var of varlist yqdum1-yqdum17 {
	gen intxn`var'_7t10=`var'*dspp0_7t10*treated_dlq 
	gen p`var'_7t10=`var'*dspp0_7t10 
	gen t`var'_7t10=`var'*treated_dlq 
}
probit transfer intxnyqdum* dspp0_7t10 treated_dlq dspp0_7t10_treated_dlq pyqdum* tyqdum* yqdum* orig_ltv securwac securocc orig_dscrnoi2 age balratio ltv occrate dscrnoi i.propid i.dealtypeid i.originatorid i.msayq i.ssid i.origyq if yearmonth>=572 & yearmonth<=620 & nouse2==0 & dcountss_2==1 & indic!=1,cluster(masterloanidtrepp) difficult
est sto baseline
label var intxnyqdum1_7t10 "2007Q3"
label var intxnyqdum2_7t10 "2007Q4"
label var intxnyqdum3_7t10 "2008Q1"
label var intxnyqdum4_7t10 "2008Q2"
label var intxnyqdum5_7t10 "2008Q3"
label var intxnyqdum6_7t10 "2008Q4"
label var intxnyqdum7_7t10 "2009Q1"
label var intxnyqdum8_7t10 "2009Q2"
label var intxnyqdum10_7t10 "2009Q4"
label var intxnyqdum11_7t10 "2010Q1"
label var intxnyqdum12_7t10 "2010Q2"
label var intxnyqdum13_7t10 "2010Q3"
label var intxnyqdum14_7t10 "2010Q4"
label var intxnyqdum15_7t10 "2011Q1"
label var intxnyqdum16_7t10 "2011Q2"
label var intxnyqdum17_7t10 "2011Q3"

coefplot baseline,keep(intxnyqdum1_7t10 intxnyqdum2_7t10 intxnyqdum3_7t10 intxnyqdum4_7t10 intxnyqdum5_7t10 intxnyqdum6_7t10 intxnyqdum7_7t10 intxnyqdum8_7t10 intxnyqdum10_7t10 intxnyqdum11_7t10 intxnyqdum12_7t10 intxnyqdum13_7t10 intxnyqdum14_7t10 intxnyqdum15_7t10 intxnyqdum16_7t10 intxnyqdum17_7t10) vertical coeflabel(,angle(45)) 
graph export "<directory>", as(png) name("Graph") replace